import App from './App'

// #ifndef VUE3
import Vue from 'vue'
import uView from '@/uni_modules/uview-ui'
import { myRuquest } from './util/api.js'
Vue.prototype.$myRuquest = myRuquest
import Axios from 'axios'	
Axios.interceptors.request.use(config => {
    var token = uni.getStorageSync('token')
    if(token){
        config.headers={token:token}
    }
	console.log(config)
	return config
})
Vue.prototype.$axios = Axios
Vue.prototype.$getlogin = function(){
    var loginid = uni.getStorageSync("loginId")
    if(!loginid){
        uni.navigateTo({
            url:'/pages/login/applogin'
        })
        return false
    }else{
        
    return true
    }
}
Vue.use(uView)
Vue.config.productionTip = false
App.mpType = 'app'
// #ifdef APP-PLUS
Vue.prototype.$host = '101.43.223.224'

// #endif

// #ifdef H5
Vue.prototype.$host = 'localhost'
// #endif

Vue.prototype.$port = '8088'
uni.addInterceptor('request',{
    invoke(e){
        var token = uni.getStorageSync('token')
        if(token){
            e.header ={token:token}
        }
        console.log(e)
        return e
    }
})
uni.addInterceptor('switchTab',{
    invoke(e){
        uni.closeSocket({
            success() {
                console.log('websocket以关闭')
            }
        })
            var url = e.url
            console.log(url)
            if(url =="/pages/mine/mine/mine"||url=="/pages/publish/publish"){
                var loginid = uni.getStorageSync("loginId")
                if(!loginid){
                    uni.navigateTo({
                        url:'/pages/login/applogin'
                    })
                    return false
                }
            }
    }
})
uni.addInterceptor('navigateTo',{
    invoke(e){
        uni.closeSocket({
            success() {
                console.log('websocket以关闭')
            }
        })
    }
})
const app = new Vue({
    ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif